package com.zst.amqp.entity;

import com.zst.amqp.utils.DateUtils;
import com.zst.amqp.utils.JsonUtils;

/**
 * 消息内容的承载DTO类
 *
 * @author zst
 */
public class MessageDTO {
    /** 消息的内容*/
    private String content;
    /** 消息的路由key*/
    private String routingKey;
    /** 消息的发送时间*/
    private String sendTime;

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getRoutingKey() {
        return routingKey;
    }

    public void setRoutingKey(String routingKey) {
        this.routingKey = routingKey;
    }

    public String getSendTime() {
        return sendTime;
    }

    public void setSendTime(String sendTime) {
        this.sendTime = sendTime;
    }

    /**
     * 创建消息DTO
     * @param content
     * @param routingKey
     * @return
     */
    public static MessageDTO create(String content, String routingKey) {
        MessageDTO dto = new MessageDTO();
        dto.setContent(content);
        dto.setRoutingKey(routingKey);
        dto.setSendTime(DateUtils.now());
        return dto;
    }

    /**
     * 根据json字符串转化成消息dto实例
     * @param json
     * @return
     */
    public static MessageDTO jsonToDTO(String json) {
        return JsonUtils.jsonStringToObject(json, MessageDTO.class);
    }
}
